<!--
 * @Author: zhoupei
 * @LastEditTime: 2023-07-14 15:20:21
 * @Description: 图片列表组件
-->
<template>
  <div :style="{ width: width }">
    <ul v-infinite-scroll="load" class="infinite-list" :style="{ overflow: 'auto', height: height }">
      <li v-for="(group, index) in groups" :key="index" class="infinite-list-item" :style="{ height: rowHeight }">
        <el-row style="margin-left: -15px; margin-top: -5px;">
          <el-col v-for="item in group" :key="item.src" :span="6">
            <div v-if="group.length == 1" style="position: relative;padding-right: 1350px; padding-top: 9px;"
              @mouseover="item.select = true" @mouseout="item.select = false">
              <el-icon size="30" class="icon-overlay" color="white" @mouseover="item.select = true"
                :style="{ marginTop: '9px', marginLeft: '407px', backgroundColor: 'rgb(238, 100, 20)', display: item.select ? 'block' : 'none' }">
                <Download />
              </el-icon>
              <el-image :style="{ width: imageWidth, height: imageHeight }" :src="item.src" fit="fill" />
            </div>
            <div v-if="group.length == 2" style="position: relative;padding-right: 450px; padding-top: 9px;"
              @mouseover="item.select = true" @mouseout="item.select = false">
              <el-icon size="30" class="icon-overlay" color="white" @mouseover="item.select = true"
                :style="{ marginTop: '9px', marginLeft: '407px', backgroundColor: 'rgb(238, 100, 20)', display: item.select ? 'block' : 'none' }">
                <Download />
              </el-icon>
              <el-image :style="{ width: imageWidth, height: imageHeight }" :src="item.src" fit="fill" />
            </div>
            <div v-if="group.length == 3" style="position: relative;padding-right: 158px; padding-top: 9px;"
              @mouseover="item.select = true" @mouseout="item.select = false">
              <el-icon size="30" class="icon-overlay" color="white" @mouseover="item.select = true"
                :style="{ marginTop: '9px', marginLeft: '407px', backgroundColor: 'rgb(238, 100, 20)', display: item.select ? 'block' : 'none' }">
                <Download />
              </el-icon>
              <el-image :style="{ width: imageWidth, height: imageHeight }" :src="item.src" fit="fill" />
            </div>
            <div v-if="group.length == 4" style="position: relative;padding-right: 10px; padding-top: 9px;"
              @mouseover="item.select = true" @mouseout="item.select = false">
              <el-icon size="30" class="icon-overlay" color="white" @mouseover="item.select = true"
                :style="{ marginTop: '9px', marginLeft: '407px', backgroundColor: 'rgb(238, 100, 20)', display: item.select ? 'block' : 'none' }">
                <Download @click="download(item.src)" />
              </el-icon>
              <el-image :style="{ width: imageWidth, height: imageHeight }" :src="item.src" fit="fill" />
            </div>
          </el-col>
        </el-row>
      </li>
    </ul>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted, computed } from "vue";
import { Draw } from '@/typings/chat';
const props = defineProps({
  height: {
    type: String,
    required: true
  },
  width: {
    type: String,
    required: true
  },
  rowHeight: {
    type: String,
    required: false
  },
  imageHeight: {
    type: String,
    required: true
  },
  imageWidth: {
    type: String,
    required: true
  },
  data: Array as () => Draw[],
  default: () => []
});

const count = ref(100)
const load = () => {
  count.value += 2
}

onMounted(() => {
})
// 将 props.data 转换为响应式对象
const dataRef = ref(props.data || []);
// 计算分组后的数据
const groups = computed(() => {
  const result = []
  for (let i = 0; i < dataRef.value.length; i += 4) {
    result.push(dataRef.value.slice(i, i + 4))
  }
  return result
})
function download(src: string) {
  // window.location.href = src;
  window.open(src);
}
</script>

<style>
.infinite-list {
  height: 910px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.infinite-list .infinite-list-item {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 500px;
  background: var(--el-color-primary-light-9);
  margin: 10px;
  color: var(--el-color-primary);
}

.infinite-list .infinite-list-item+.list-item {
  margin-top: 10px;
}

.icon-overlay {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
}
</style>